<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
    <!-- 模板标签用大驼峰，与注册名称一致 -->
    <CwJbszqkzbZhuForm
      ref="realForm"
      @ok="submitCallback"
      :disabled="disableSubmit"
      :scene="currentScene"
    />
  </j-modal>
</template>

<script>
// 确保导入路径与 Form 文件名完全一致（大小写敏感）
import CwJbszqkzbZhuForm from './CwJbszqkzbZhuForm'

export default {
  name: 'CwJbszqkzbZhuModal',
  components: {
    CwJbszqkzbZhuForm // 注册名称与导入名称一致
  },
  data() {
    return {
      title: '',
      visible: false,
      disableSubmit: false,
      currentScene: ''
    }
  },
  methods: {
    add() {
      this.currentScene = 'add';
      this.title = '新增基本收支情况总表';
      this.visible = true;
      this.disableSubmit = false;

      // 双重确保：$nextTick + setTimeout，保证 Form 渲染完成
      this.$nextTick(() => {
        setTimeout(() => {
          if (this.$refs.realForm) {
            console.log('Modal 新增：找到 Form 组件，场景传递 add');
            this.$refs.realForm.addBefore('add');
          } else {
            console.error('Modal 未找到 Form 组件！排查步骤：');
            console.error('1. 检查 Form 组件文件名是否为 CwJbszqkzbZhuForm.vue');
            console.error('2. 检查导入路径是否正确（./CwJbszqkzbZhuForm）');
            console.error('3. 检查 Form 组件内部是否有语法错误（如控制台其他报错）');
          }
        }, 0);
      });
    },

    edit (record) {
      this.visible=true
      this.$nextTick(()=>{
        this.$refs.realForm.edit(record);
      })
    },

    close() {
      this.$emit('close');
      this.visible = false;
      this.currentScene = '';
      this.title = '';
    },

    handleOk() {
      if (this.$refs.realForm) {
        this.$refs.realForm.handleOk();
      } else {
        console.error('提交失败：未找到 Form 组件');
      }
    },

    submitCallback() {
      this.$emit('ok');
      this.visible = false;
      this.currentScene = '';
      this.title = '';
    },

    handleCancel() {
      this.close();
    }
  }
}
</script>

<style scoped>
</style>